package com.zhongying.jf.result;

import org.apache.commons.lang3.StringUtils;

public class ResultUtils {

    private static String SUCCESS_CODE = "0";
    private static String FAIL_CODE = "-1";

    public static <T> Result<T> newSuccessResult(){
        Result<T> result = new ResultSupport<>();
        result.setCode(SUCCESS_CODE);
        return result;
    }

    public static <T> Result<T> newSuccessResult(T model){
        Result<T> result = new ResultSupport<>();
        result.setCode(SUCCESS_CODE);
        result.setModel(model);
        return result;
    }

    public static <T> Result<T> newFailResult(String msg){
        Result<T> result = new ResultSupport<>();
        result.setCode(FAIL_CODE);
        result.setMsg(msg);
        return result;
    }

    public static boolean isSuccess(Result result){
        return result != null ? StringUtils.equals(result.getCode(), SUCCESS_CODE) : false;
    }
}
